home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / mfsdefrg.zoo / defrag.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-14  |  5.1 KB  |  193 lines

  1. /*
  2.  * defrag.h - include file for the Linux file system degragmenter.
  3.  * defrag.h,v 1.7 1993/01/07 14:48:49 linux Exp
  4.  *
  5.  * Copyright (C) 1992, 1993 Stephen Tweedie (sct@dcs.ed.ac.uk)
  6.  *
  7.  * Copyright (C) 1992 Remy Card (card@masi.ibp.fr)
  8.  *
  9.  * Copyright (C) 1991 Linus Torvalds (torvalds@kruuna.helsinki.fi)
  10.  * 
  11.  * This file may be redistributed under the terms of the GNU General
  12.  * Public License.
  13.  *
  14.  */
  15.  
  16. #ifdef NODEBUG
  17.  #define debug 0
  18.  #define assert(a)
  19. #else
  20.  extern int debug;
  21.  #include <assert.h>
  22. #endif
  23.  
  24. #ifdef EXTFS
  25. #include "ext.h"
  26. #endif
  27. #ifdef MINIXFS
  28. #include "minix.h"
  29. #endif
  30.  
  31. /* Use inline assembler to generate efficient bit operators */
  32. #ifndef __GNUC__
  33. #error "needs gcc for the bitop-__asm__'s"
  34. #endif
  35.  
  36. #define SYNC_PERIOD 500
  37.  
  38. extern char * program_name, * version, * CVSID;
  39. extern char * device_name;
  40. extern int IN;
  41. extern int verbose, show, show_version, badblocks, readonly;
  42. extern int blocks_until_sync;
  43.  
  44. extern int changed; /* flags if the filesystem has been changed */
  45.  
  46. /* We omit a lot of the declarations when compiling misc.c, since
  47.    misc.o is shared between extfs and minixfs versions, so we can't
  48.    give correct types for a lot of fs-dependent stuff. */
  49.  
  50. #ifndef MISC_C
  51.  
  52. extern Block next_block_to_fill, first_zone;
  53. extern unsigned int zones, block_size;
  54.  
  55. extern char * inode_buffer;
  56. #define Inode        (((struct d_inode *) inode_buffer) - 1)
  57. extern char super_block_buffer[];
  58.  
  59. /* n2d_map and d2n_map contain the zone movement maps.  Whenever a zone is
  60.    moved, these maps are updated to allow the current occupant of a zone
  61.    to be mapped to its original location, and the original location of any
  62.    zone data to be mapped to its current location.
  63.  
  64.    When a zone was originally empty, the d2n_map will contain zero at
  65.    that location to reflect the fact that there was no original occupant
  66.    of that zone is not to be found.  The n2d_map will also be zero for
  67.    blocks which do not currently hold any useful data and which may be
  68.    overwritten freely.
  69.  
  70.    o2n_map contains the final translation from  old to new disc
  71.    blocks, and is used to update inode block tables and indirection
  72.    blocks.
  73.  
  74.    inode_map and bad_map maintain flags recording which inodes are in
  75.    use, and which blocks are bad respectively.
  76. */
  77.  
  78. extern char * inode_map;
  79. extern Block *inode_average_map;
  80. extern int *inode_order_map;
  81.  
  82. extern Block *n2d_map, *d2n_map, *o2n_map;
  83.  
  84. /* Manipulate the inode map */
  85. #define inode_in_use(x)    (bit (inode_map, (x)))
  86. #define mark_inode(x)    (setbit (inode_map, (x)), changed = 1)
  87. #define unmark_inode(x)    (clrbit (inode_map, (x)), changed = 1)
  88.  
  89. /* Manipulate the block translation maps */
  90. #define n2d(x)        (n2d_map[(x)-first_zone])
  91. #define d2n(x)        (d2n_map[(x)-first_zone])
  92. #define o2n(x)        (o2n_map[(x)-first_zone])
  93.  
  94. #define unmark_zone(x)    (d2n(x) = 0, n2d(x) = 0, changed = 1)
  95. #define zone_in_use(x)    (n2d(x) != 0)
  96.  
  97. #ifdef EXTFS
  98. /* Manipulate the bad block map */
  99. extern char * bad_map;
  100. #define zone_is_bad(x)    (bit (bad_map, (x) - first_zone + 1))
  101. #define mark_bad(x)    (setbit (bad_map, (x) - first_zone + 1), badblocks++)
  102. #endif
  103.  
  104.  
  105. /* Define modes for the walk_zone functions */
  106. enum walk_zone_mode {WZ_SCAN, WZ_REMAP_IND, WZ_REMAP_DATA
  107. #ifdef EXTFS
  108.                  , WZ_BAD_BLOCKS
  109. #endif
  110.                  };
  111.  
  112. /* Miscellaneous function declarations */
  113.  
  114. /* The inline bitop functions... */
  115. #ifdef atarist
  116. #include <portst.h>
  117. #else
  118.  
  119. #define bitop(name,op) \
  120. static inline int name(char * addr,unsigned int nr) \
  121. { \
  122.     int __res; \
  123.     __asm__ __volatile__("bt" op "l %1,%2; adcl $0,%0" \
  124.         :"=g" (__res) \
  125.         :"r" (nr),"m" (*(addr)),"0" (0)); \
  126.     return __res; \
  127. }
  128.  
  129. bitop(bit,"")
  130. bitop(setbit,"s")
  131. bitop(clrbit,"r")
  132. #endif
  133.  
  134. extern int isatty(int);
  135.  
  136. /* Block/buffer management prototypes */
  137. enum BufferType { OUTPUT, RESCUE };
  138. typedef enum BufferType BufferType;
  139.     
  140. typedef struct Buffer Buffer;
  141. struct Buffer
  142. {
  143.     BufferType btype : 1;
  144.     unsigned int in_use : 1;
  145.     unsigned int full : 1;
  146.     Buffer *next;
  147.     Block dest_zone;
  148.     unsigned char data[0];
  149. };
  150.  
  151.  
  152. extern int pool_size;
  153. extern Buffer *pool;
  154.  
  155. extern int count_buffer_writes, count_buffer_reads;
  156. extern int count_write_groups, count_read_groups;
  157. extern int count_buffer_migrates, count_buffer_forces;
  158. extern int count_buffer_read_aheads;
  159.  
  160. void read_buffer_data (Buffer *b);
  161. void write_buffer_data_at (Buffer *b, Block dest);
  162. void write_buffer_data (Buffer *b);
  163.  
  164. void init_buffer_tables (void);
  165. void remap_disk_blocks (void);
  166.  
  167. void check_zone_nr (Block nr);
  168. /* Read/write block currently at given address */
  169. void read_current_block (Block nnr, char * addr);
  170. void write_current_block (Block nnr, char * addr);
  171. /* Read/write block originally at given address */
  172. void read_old_block (Block onr, char *addr);
  173. void write_old_block (Block onr, char *addr);
  174.  
  175. /* Prototypes for fs-specific portions */
  176. void read_tables (void);
  177. void write_tables (void);
  178. void salvage_free_zones (void);
  179. void init_zone_maps (void);
  180. void init_inode_bitmap (void);
  181.  
  182. #endif /* MISC_C */
  183.  
  184. /* Now for the prototypes for misc.c */
  185.  
  186. /* Volatile to let gcc know that this doesn't return. */
  187. volatile void fatal_error ();
  188. volatile void usage ();
  189.  
  190. #define die(str)    fatal_error("%s: " str "\n")
  191. #define nomore()    fatal_error("%s: cannot continue.\n")
  192.  
  193.